package com.xuecheng.manage_cms.service.impl;

import com.xuecheng.framework.domain.cms.CmsSite;
import com.xuecheng.framework.model.response.CommonCode;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.framework.model.response.QueryResult;
import com.xuecheng.manage_cms.dao.CmsSiteRepository;
import com.xuecheng.manage_cms.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Kidy
 * @date 2020/6/19 20:07
 */
@Service
public class SiteServiceImpl implements SiteService {

    @Autowired
    private CmsSiteRepository cmsSiteRepository;

    @Override
    public QueryResponseResult findAllName() {
        List<CmsSite> cmsSites = cmsSiteRepository.findAll();
        QueryResult<Map<String, String>> queryResult = new QueryResult<>();
        queryResult.setList(cmsSites.stream().map(site -> {
            HashMap<String, String> map = new HashMap<>();
            map.put("siteId", site.getSiteId());
            map.put("siteName", site.getSiteName());
            return map;
        }).collect(Collectors.toList()));
        queryResult.setTotal(cmsSites.size());
        QueryResponseResult queryResponseResult = new QueryResponseResult(CommonCode.SUCCESS, queryResult);
        return queryResponseResult;
    }
}
